from kivy.uix.widget import Widget
from kivy.properties import DictProperty

from goblinoid.services.profile_service import ProfileService


class ProfileManager(Widget):
    profile_services = DictProperty()

    def on_refresh(self, **kwargs):
        for profile in self.profile_services:
            self.profile_services[profile].on_refresh(**kwargs)

    def add_profile(self, profile):
        webfinger = unicode(profile)
        if webfinger not in self.profile_services:
            self.profile_services[webfinger] = ProfileService(
                pump_profile=profile)
        else:
            self.profile_services[webfinger].update_profile(profile)

    def get_profile_service(self, webfinger):
        return self.profile_services[webfinger]

    def clear_profile_services(self):
        self.profile_services.clear()
